import { Tween, Node } from "cc"
import { ClientEvent } from "./framework/ClientEvent"
import { GUIDE_STATE } from "./framework/constant"
import { Size } from "cc"

export class GlobalData {
  private static _instance: GlobalData = null

  public static get instance(): GlobalData {
    if (!GlobalData._instance) GlobalData._instance = new GlobalData()
    return GlobalData._instance
  }

  public arrNodePlayerRole: Node[] = []

  public arrNodeMonster: Node[] = []

  public nodeGame: Node = null

  public nodePlayer: Node = null

  public isGameStart: boolean = false

  public isGameOver: boolean = false

  public isGamePause: boolean = false

  public isGuideCompound: boolean = false

  public numMonsterSlow: number = 0

  /**boss狂暴状态 */
  public isBossRage: boolean = false

  public arrRoleDamage: number[] = [0, 0, 0, 0, 0]

  public arrRoleBeDamage: number[] = [0, 0, 0, 0, 0]

  public winSize: Size = new Size()
  public getGameState() {
    return this.isGameStart && !this.isGameOver && !this.isGamePause
  }

  public gGameSpeed: number = 1
  //-----当前buff属性模块-----
  public monsterData: any

  public levelData: any

  public roleData: any

  public maxMonsterCount: number = 0
  private _curMonsterCount: number = 0
  public set curMonsterCount(value: number) {
    this._curMonsterCount = value
    ClientEvent.emit("onGameMonsterCountChange")
  }
  public get curMonsterCount() {
    return this._curMonsterCount
  }

  private _curLevel: number = 0
  public set curLevel(value: number) {
    this._curLevel = value
    ClientEvent.emit("onGameLevelChange")
  }
  public get curLevel() {
    return this._curLevel
  }

  private _coinValue: number = 0
  public set coinValue(value: number) {
    this._coinValue = value
    ClientEvent.emit("onCoinValueChange")
  }
  public get coinValue() {
    return this._coinValue
  }

  private _expValue: number = 0
  public set expValue(value: number) {
    this._expValue = value
    ClientEvent.emit("onExpValueChange")
  }
  public get expValue() {
    return this._expValue
  }

  private _gemValue: number = 0
  public set gemValue(value: number) {
    this._gemValue = value
    ClientEvent.emit("onGemValueChange")
  }
  public get gemValue() {
    return this._gemValue
  }

  /**游戏血量 */
  private _gamePlayerHp: number = 1000
  public maxGamePlayerHp: number = 1000
  public get gamePlayerHp() {
    return this._gamePlayerHp
  }
  public set gamePlayerHp(value: number) {
    this._gamePlayerHp = Math.max(value, 0)
    ClientEvent.emit("onGamePlayerHpChange")
  }

  private _gAttack: number = 1
  public set gAttack(value: number) {
    this._gAttack = value
    ClientEvent.emit("onGAttackChange")
  }
  public get gAttack() {
    return this._gAttack
  }

  private _gDefense: number = 1
  public set gDefense(value: number) {
    this._gDefense = value
    ClientEvent.emit("onGDefenseChange")
  }
  public get gDefense() {
    return this._gDefense
  }

  private _gHealthRecovery: number = 1
  public set gHealthRecovery(value: number) {
    this._gHealthRecovery = value
    ClientEvent.emit("onGHealthRecoveryChange")
  }
  public get gHealthRecovery() {
    return this._gHealthRecovery
  }

  private _gAttackSpeed: number = 1
  public set gAttackSpeed(value: number) {
    this._gAttackSpeed = value
    ClientEvent.emit("onGAttackSpeedChange")
  }
  public get gAttackSpeed() {
    return this._gAttackSpeed
  }

  public getCurrPlayerAttack() {
    return (GlobalData.instance.gAttack - 1) * 1
  }

  public getCurrPlayerAttackSpeed() {
    let speed: number = 1
    if (GlobalData.instance.gAttackSpeed >= 2) {
      speed = Math.max(0.12,Math.pow(0.93, GlobalData.instance.gAttackSpeed - 2) * 0.8)
    }
    return speed
  }

  public getCurrPlayerDefense() {}

  public gCurrGuide: GUIDE_STATE = GUIDE_STATE.NONE
}
